angular.module('Controller')

.controller('QgyCheckInCtrl', ($scope,NgTableParams,menuManage,wfAlert,$localStorage,commonUtil,commonConstant,$rootScope,$uibModal,$http) ->
    $scope.info={
        checkType:undefined
        startCheckIn:false
    }
    $scope.checkTypeList=[{value:'contract',name:'线上入住'},{value:'manual',name:'线下入住'}]
#    $scope.payTypeList=commonConstant.payTypeList(true)
    $scope.sexList=commonConstant.numSexList()

    _.extend $scope,
        pickContract:()->
            showContractModal()
        goOnline:(contract)->
            $scope.contractData=contract
            $scope.info.checkType='contract'
            $scope.info.startCheckIn=true
        goOffline:()->
            $scope.info.checkType='manual'
            $scope.info.startCheckIn=true
        backToEntrance:()->
            $scope.info.checkType=undefined
            $scope.contractData=undefined
            $scope.info.startCheckIn=false
        doCheckIn:()->
            ''
        printContract:()->
            ''
        openCotenant:(type,item)->
            modal=showCotenantModal(type,item)
            modal.result.then((modalData)->
                if modalData && type!='view'
                    item=modalData
            )
            ''


    showContractModal=()->
        $scope.modal = $uibModal.open({
            animation: true,
            size:'lg',
            appendTo: $("#modalContent:eq(0)"),
            controller: 'QgyPickContractModalCtrl',
            templateUrl: 'templates/business-manage/check-in/pick-contract-modal.html',
            resolve: {
                items:  ()->{data:{}}
            }
        })
        $scope.modal.result.then((modalData)->
            if modalData!=undefined && modalData.id!=undefined
                $http.get("/contract/#{modalData.id}/detail")
                .success((resp)->
                    if resp.code==0
                        $scope.goOnline(resp.message)
                )
        )
    showCotenantModal=(type,data)->
        modal = $uibModal.open({
            animation: true,
            size:'lg',
            appendTo: $("#modalContent:eq(0)"),
            controller: 'QgyCotenantModalCtrl',
            templateUrl: 'templates/business-manage/cotenant-modal/cotenant-modal.html',
            resolve: {
                items:  ()->{type:type,data:data}
            }
        })
)